﻿$(document).ready(function () {
    //convert to fancy radio buttons
    //$("input[type=radio]").each(function () { $(this).button(); });

    //see if hidden field was set to indicate that parameter dialog should be displayed
    if ($("[id$='hdnShowParms']").val() == "true") showDialogParms();

    $("#divProgress").progressbar({
        value: false //not supported in this version (indeterminate)
    });

});

function RunReport() {
    if (PageMethods.HasParameters()) showDialogParms();
}

function showDialogParms() {

    //set default buttons for dialogs
    $(document).keypress(function (e) {
        if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
            if ($('#divDialogParms').dialog('isOpen'))
                $('[aria-labelledby$=divDialogSave]').find(":button:contains('OK')").click();
            return false;
        }
    });

    //set titles for dialogs
    PageMethods.GetResource("ReportParms", function (res) {
        $("#divDialogParms").attr("title", res);
        var dlg = $("#divDialogParms").dialog({
            modal: true,
            width: 850,
            height: 400
        })
        dlg.parent().appendTo($("form:first"));
    })

};

var progressValue = 0;

function showProgress() {
    //would be better to just show indeterminate progressbar, but not available in this version of JQuery
    //alternatively, can try to display animated GIF

    progressValue = 0;
    $("#divProgress").progressbar({
        value: 0
    });
    window.setInterval(function () {
        progressValue = (progressValue + 1) % 100;
        $("#divProgress").progressbar({ value: progressValue });
    }, 50);

    PageMethods.GetResource("ProgressTitle", function (res) {
        $("#divDialogProgress").attr("title", res);
        var dlg = $("#divDialogProgress").dialog({
            modal: true,
            width: 300,
            height: 100,
            resizable: false,
            draggable: false,
            closeOnEscape: false
        })
    })
};

